package com.ruoyi.system.domain;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.system.domain.deviceAlarm.DeviceAlarm;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
public class DeviceDetail extends BaseEntity {

    private String deviceId;

    private List<Device> reports;

    private List<DeviceAlarm> alarms;

    public DeviceDetail(String deviceId) {
        this.deviceId = deviceId;
        this.reports = new ArrayList<>();
        this.alarms = new ArrayList<>();
    }

    public void put(String name, List<JSONObject> dataList) {
        switch (name) {
            case "REPORT":
                dataList.forEach(this::addReport);
                break;
            case "ALARM":
                dataList.forEach(this::addAlarm);
                break;
            default:
                // Handle unknown type or log an error
                break;
        }
    }

    private void addReport(JSONObject jsonObject) {
        reports.add(new Device(jsonObject));
    }

    private void addAlarm(JSONObject jsonObject) {
        alarms.add(new DeviceAlarm(jsonObject));
    }
}
